//
//  KKStudyHttp.m
//  DoMi
//
//  Created by 康凯 on 16/10/28.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKStudyHttp.h"
#import "KKStudyItem.h"
#import "KKStudyList.h"
#import "KKVideoDetail.h"
#import "KKCommentM.h"
#import "KKBuyVideoM.h"
#import "KKBannerM.h"
#import "KKSearchM.h"
#import "KKPayInfoM.h"
#import "KKHotSearchM.h"

@implementation KKStudyHttp

#pragma mark 头部item
+(void)getTopItem:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:STUDY_ITEM params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyItem mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 首页本月最佳
+(void)getBestList:(NSDictionary *)params success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:STUDY_BEST_LIST params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyList mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 首页列表
+(void)getHomeList:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:STUDY_HOME_LIST params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyList mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 头部item列表
+(void)getTopItemList:(NSDictionary *)params success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:ENTRY_STUDY_ITEM params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyList mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频详情页
+(void)getVideoDetail:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:STUDY_VIDEO_DETAIL params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            KKVideoDetail *datas=[KKVideoDetail mj_objectWithKeyValues:responseObject];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频文章收藏
+(void)addCollect:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:ADD_COLLECT params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *count=[responseObject objectForKey:@"coun"];
            success(count);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频文章取消收藏
+(void)cancleCollect:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:CANCLE_COLLECT params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *count=[responseObject objectForKey:@"coun"];
            success(count);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频点赞
+(void)addVideoLike:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:VIDEO_LIKE params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *count=[responseObject objectForKey:@"coun"];
            success(count);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 评论点赞
+(void)addCommentLike:(NSString *)commentId success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"commentid":commentId};
    [KKBaseHttp Post:COMMENT_LIKE params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *count=[responseObject objectForKey:@"coun"];
            success(count);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 相关视频列表
+(void)getRelateVideoList:(NSString *)videoId success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"videoid":videoId};
    [KKBaseHttp Post:STUDY_RELATE_VIDEO_LIST params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyList mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 评论列表
+(void)getCommentList:(NSDictionary *)params success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:COMMENT_List params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKCommentM mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频回复列表
+(void)getReplyList:(NSString *)commentId success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"commentid":commentId};
    [KKBaseHttp Post:COMMENT_REPLY_List params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKCommentM mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 视频播放权限
+(void)getVideoPermission:(NSString *)videoId success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"videoid":videoId};
    [KKBaseHttp Post:VIDEO_PERMISSION params:params success:^(id responseObject) {
        success(responseObject);
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 视频购买信息
+(void)getVideoBuyInfo:(NSString *)videoId success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"videoid":videoId};
    [KKBaseHttp Post:BUY_VIDEO_INFO params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            KKBuyVideoM *datas=[KKBuyVideoM mj_objectWithKeyValues:responseObject];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 增加评论
+(void)addComment:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:ADD_COMMENT params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *msg=[responseObject objectForKey:@"msg"];
            success(msg);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 评论回复
+(void)addVideoReply:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:ADD_VIDEO_REPLY params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *msg=[responseObject objectForKey:@"msg"];
            success(msg);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 获取排行榜
+(void)getRankList:(NSString *)type success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"type":type};
    [KKBaseHttp Post:RANK params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKStudyList mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 获取搜索列表
+(void)getSearchList:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:SEARCH params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKSearchM mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 获取首页banner
+(void)getBannerInfo:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN};
    [KKBaseHttp Post:BANNER params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSArray *list=[responseObject objectForKey:@"list"];
            NSArray *datas=[KKBannerM mj_objectArrayWithKeyValuesArray:list];
            success(datas);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
    }];
}
#pragma mark 分享视频回调
+(void)shareVideoCallBack:(NSString *)videoId success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"videoid":videoId};
    [KKBaseHttp Post:VIDEO_SHARE params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *count=[responseObject objectForKey:@"coun"];
            success(count);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 视频积分支付
+(void)payJiFenVideo:(NSString *)videoId success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"videoid":videoId};
    [KKBaseHttp Post:PAY_JIFEN_VIDEO params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *msg=[responseObject objectForKey:@"msg"];
            success(msg);
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 得到调起支付信息
+(void)getPayVideoInfo:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    [KKBaseHttp Post:PAY_VIDEO params:params success:^(id responseObject) {
        NSString *code=[responseObject objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            NSString *code=[responseObject objectForKey:@"code"];
            if([code isEqualToString:@"ok"]){
                NSString *orderinfo=[responseObject objectForKey:@"orderinfo"];
                success(orderinfo);
            }else{
                NSString *msg=[responseObject objectForKey:@"msg"];
                [self toast:msg];
            }
        }else{
            NSString *msg=[responseObject objectForKey:@"msg"];
            [self toast:msg];
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 热门搜索
+(void)getHotSearchList:(void (^)(id))success failure:(void (^)(NSError *))failure{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN};
    [KKBaseHttp Post:HOT_SEARCH params:params success:^(id responseObject) {
        NSArray *list=[responseObject objectForKey:@"list"];
        NSArray *datas=[KKHotSearchM mj_objectArrayWithKeyValuesArray:list];
        success(datas);
    } failure:^(NSError *error) {
        
    }];
}
@end
